from django import forms
from django.contrib.auth.models import User

from ff_app.models import FarmerFile


class LoginForm(forms.Form):
    username = forms.CharField(label='用户名', min_length=3)
    password = forms.CharField(label='密码',
                               widget=forms.PasswordInput)

    def clean_username(self):
        user_name = self.cleaned_data['username']
        user = User.objects.filter(username=user_name)
        if not user.exists():
            self.add_error('username', '用户名不存在')
        return user_name


class FarmerFileForm(forms.ModelForm):
    class Meta:
        model = FarmerFile
        # fields = '__all__'
        exclude = ['status', 'loan_limit', 'farmer', 'staff']
